<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>TXT数据请求</title>
    <script type="text/javascript">
        /* 异步请求 */
        function function_1(){
            let object=new XMLHttpRequest();
            object.open('get','./../asset/info.txt',true);
            object.send();
            object.onreadystatechange=function(){
                if (object.readyState===4 && object.status===200){
                    document.querySelector("#asynchronous").innerHTML=object.responseText;
                }
            }
        }

        /* 同步请求 */
        function function_2(){
            let object=new XMLHttpRequest();
            object.open('get','./../asset/info.txt',false);
            object.send();
            document.querySelector("#synchronous").innerHTML=object.responseText;
        }
    </script>
</head>
<body>
点击按钮获取info.txt的文本数据（异步请求）<br>
<button type="button" onclick="function_1()">请求信息</button><br>
获得的信息：<span id="asynchronous"></span>
<hr>
点击按钮获得info.txt的文本数据（同步请求）<br>
<button type="button" onclick="function_2()">请求信息</button><br>
获得的信息：<span id="synchronous"></span>
</body>
</html>